package com.grape.juc.lock.reentrant;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 描述:ReentrantLock
 * @author: myx
 * @date: 2019-05-08
 * Copyright © 2019-grape. All rights reserved.
 */
public class ReentrantLockTest implements Runnable{
    Lock lock=new ReentrantLock();

    public  void get() {
        try {
            lock.lock();
            System.out.println("name:" + Thread.currentThread().getName() + " get();");
            set();
        }catch (Exception e){
        }finally {
            lock.unlock();
        }
    }
    public  void set() {
        try {
            lock.lock();
            System.out.println("name:" + Thread.currentThread().getName() + " set();");
        }catch (Exception e){
        }finally {
            lock.unlock();
        }
    }

    @Override
    public void run() {
        get();
    }
    public static void main(String[] args) {
        ReentrantLockTest ss = new ReentrantLockTest();
        new Thread(ss).start();
        new Thread(ss).start();
        new Thread(ss).start();
        new Thread(ss).start();
    }
}

